package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class demo14 {
    private static Object locker = new Object();
    private static Integer count = 0;
    static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            try {
                //加锁
                lock.tryLock(111, TimeUnit.SECONDS);
                for (int i = 0; i < 100; i++) {
                    count++;
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                //解锁
                lock.unlock();
            }
        });
        t.start();
        t.join();
        System.out.println(count);
    }

}
